/*
 * @Author: CB
 * @Date: 2023-01-29 10:18:12
 * @Descripttion: 单例
 */
export default function Singleton<T>() {
    class Singleton {
        protected constructor() { }

        protected static _Instance: Singleton = null;

        public static get ins(): T {
            if (!Singleton._Instance) {
                Singleton._Instance = new this();
                Singleton._Instance.singleInit();
            }
            return Singleton._Instance as T;
        }

        public static set ins(v: Singleton | null) {
            if (v) {
                Singleton._Instance = v;
            } else {
                delete Singleton._Instance;
            }
        }

        protected singleInit() {
        }
    }
    return Singleton;
}